﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using SpaceMan.Physics;
namespace SpaceMan.Entities
{
    class C_PRJ_StandardBullet : I_Projectile
    {
        float lifeTime, Direction;

        public C_PRJ_StandardBullet(Vector2 Position, float Direction, Vector2 Velocity,DamageAffinity damageAffinity)
        {
            Position -= new Vector2(34, 48);
            lifeTime = 2000;
            this.Direction = Direction;
            List<PHY_Collider> hurtList = new List<PHY_Collider>();
            PHY_Hurt hurt = new PHY_Hurt();
            hurt.Initialize(new Vector2(27,41), 13, 13, false, 20, damageAffinity, destroySelf);
            hurtList.Add(hurt);
            rigid = new PHY_Base(Position, 1,1, false, hurtList, null, this.GetType().Name);
            Vector2 vector2Direction = new Vector2((float)Math.Sin(Direction), -(float)Math.Cos(Direction));
            rigid.Addforce(vector2Direction * 2000);
            rigid.currentState.V += Velocity;
            DrawOperation = S_Global.getDraw("bullets/shot");
            InitializeBullet();
        }

        public override void Initialize(Vector2 Position)
        {

        }

        public override void Update()
        {
            lifeTime -= S_Global.getTimescale();
            DrawOperation.Update(rigid.currentState.Pos, Direction, null, null, false, null);
            Position = rigid.currentState.Pos;
            if (lifeTime <= 0)
            {
                MarkedForDeletion = true;
            }
            
        }

        public override void destroySelf()
        {
            base.MarkedForDeletion = true;
            rigid.MarkedForDeletion = true;
        }
    }
}
